'use strict';

define(['angular', 'moment'], function (angular) {
		var module = angular.module('mpjGlobalFilter', ['mpjRest']);

		module.filter('unitType', function () {
			return function (type) {
				if (type == "weight") return "重量";
				else if (type == 'capacity') return "容量";
				else return "数量";
			};
		});

		module.filter('maccTxType', function () {
			return function (type) {
				if (type == "pay") return "支付";
				else if (type == 'deposit') return "储值";
				else if (type == 'refund') return "支付回退";
				else if (type == 'manual-update') return "手动修改";
				else return type;
			};
		});

		module.filter('pointsTxType', function () {
			return function (type) {
				if (type == "pay") return "积分支付";
				else if (type == 'reward') return "消费累积";
				else if (type == 'revert') return "退货积分反扣";
				else if (type == 'refund') return "支付回退";
				else if (type == 'manual-update') return "手动修改";
				else return type;
			};
		});
		module.filter('orderType', [function (otype) {
			return function (otype) {
				if (otype == 'sales') return "销售";
				else if (otype == 'all') return "所有";
				else if (otype == 'void') return "废单";
				else if (otype == 'refund') return "退单";
				else if (otype == 'pre-order') return "点单";
				else if (otype == 'macct-deposit') return "会员充值";
				else return otype;
			}
		}]);
		module.filter('show3Invts', [function (items) {
			return function (items) {
				var strs = [];

				var items = items.slice(0, 3);
				angular.forEach(items, function (item) {
					strs.push(item);
				});
				return strs.join(',');
			}
		}]);
		// 订单类型
		module.filter('orderType', [function (otype) {
			return function (otype) {
				if (otype == 'sales') return "销售";
				else if (otype == 'all') return "所有";
				else if (otype == 'void') return "废单";
				else if (otype == 'refund') return "退单";
				else if (otype == 'pre-order') return "点单";
				else if (otype == 'macct-deposit') return "会员充值";
				else return otype;
			}
		}]);
		module.filter('paychannel', [function (channel) {
			return function (channelObj) {
				var channel = channelObj.channel || channelObj;

				var result = '';
				if (channel == "cash") result = '现金';
				else if (channel == "member-account") result = '会员账户支付';
				else if (channel == "member-points") result = '会员积分支付';
				else result = channel;

				if (channelObj.subchannel) {
					if (channelObj.subchannel == 'storepay') {
						result += '(店员代扣)';
					} else if (channelObj.subchannel == 'passpay') {
						result += '(密码支付)';
					}
					else if (channelObj.subchannel == 'mstorepay') {
						result += '(微网站支付)';
					}
					else if (channelObj.subchannel == 'vcodepay') {
						result += '(会员扫码支付)';
					}
				}
				return result;
			}
		}])
		module.directive('autoFocusInput', function () {
			return function (s, e, a) {
				if (!s.initInvt) {
					setTimeout(function () {
						e[0].focus();
					}, 100);
				}
			};
		});
	}
)